using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SchnelleKarten
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        
        //Menu Textures
        Texture2D mainMenu, gamePlayScreen, buttonBackground;

        //Button Textures
        Texture2D playBTN, disPlayBTN;
        bool playBTNDown = false;
        Texture2D exitBTN, disExitBTN;
        bool exitBTNDown = false;

        //Miscellaneous Textures
        Texture2D selectionRing;
        Texture2D outlineRing;

        //Hacky Screen Manager
        bool isMainScreen;
        bool isGameScreen;

        //Ridiculous Global Things
        bool canSelectHand;
        bool handSelect;

        bool canSelectWork;
        bool workSelect;
        bool firstWork;
        bool secondWork;
        bool thirdWork;
        bool fourthWork;
        int workPile;

        int communePile;

        bool canSelectSchnelle;
        bool schnelleSelect;
        int pSchnelleCard;

        bool addedCard;

        #region Player Informations
        Deck   playerDeck;
        Card[] playerCards = new Card[3];
        Card[] pSchnelle = new Card[13];
        WorkPile pFirst;
        WorkPile pSecond;
        WorkPile pThird;
        WorkPile pFourth;
        #endregion

        #region Computer One Informations
        Deck   cOneDeck;
        Card[] cOneCards = new Card[3];
        //WorkPile
        //WorkPile
        //WorkPile
        //WorkPile
        //SchnellePile
        #endregion

        #region Computer Two Informations
        Deck   cTwoDeck;
        Card[] cTwoCards = new Card[3];
        //WorkPile
        //WorkPile
        //WorkPile
        //WorkPile
        //SchnellePile
        #endregion

        #region Computer Three Informations
        Deck   cTreDeck;
        Card[] cTreCards = new Card[3];
        //WorkPile
        //WorkPile
        //WorkPile
        //WorkPile
        //SchnellePile
        #endregion

        CommunityPile[] communityPiles;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            Window.Title  = "Schnelle Karten";
            IsMouseVisible = true;
            Components.Add(new InputManager(this));
        }

        protected override void Initialize()
        {
            isMainScreen = true;
            isGameScreen = false;

            playerDeck = new Deck(Content.Load<Texture2D>("Cards/Backs/Player"), Content);
            for (int i = 12; i >= 0; i--)
                pSchnelle[i] = playerDeck.DealCard();
            for (int i = 2; i >= 0; i--)
                playerCards[i] = playerDeck.DealCard();
            pFirst = new WorkPile(true);
            pSecond = new WorkPile(true);
            pThird = new WorkPile(true);
            pFourth = new WorkPile(true);

            cOneDeck   = new Deck(Content.Load<Texture2D>("Cards/Backs/ComputerOne"), Content);
            cTwoDeck   = new Deck(Content.Load<Texture2D>("Cards/Backs/ComputerTwo"), Content);
            cTreDeck   = new Deck(Content.Load<Texture2D>("Cards/Backs/ComputerTre"), Content);

            communityPiles = new CommunityPile[16];
            for (int i = 0; i < 16; i++)
            {
                communityPiles[i] = new CommunityPile();
            }

            selectionRing = Content.Load<Texture2D>("Cards/SelectingRing");
            outlineRing = Content.Load<Texture2D>("Cards/OutlineRing");
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            #region Menu Textures
            mainMenu         = Content.Load<Texture2D>("Menus/MainMenu");
            gamePlayScreen   = Content.Load<Texture2D>("Menus/GamePlayScreen");
            buttonBackground = Content.Load<Texture2D>("Menus/ButtonBackground");

            playBTN = Content.Load<Texture2D>("Buttons/button_Play");
            exitBTN = Content.Load<Texture2D>("Buttons/button_Exit");

            disPlayBTN = Content.Load<Texture2D>("Buttons/buttonDown_Play");
            disExitBTN = Content.Load<Texture2D>("Buttons/buttonDown_Exit");
            #endregion

        }

        protected override void Update(GameTime gameTime)
        {
            if (InputManager.IsKeyPressed(Keys.End))
                this.Exit();

            if (isMainScreen)
                UpdateMainScreen();
            else if (isGameScreen)
                UpdateGameScreen();
            
            base.Update(gameTime);
        }

        void UpdateMainScreen()
        {
            #region Play Detection
            if (InputManager.MouseXLocation >= 487 && InputManager.MouseXLocation <= 553
             && InputManager.MouseYLocation >= 217 && InputManager.MouseYLocation <= 234)
                playBTNDown = true;
            else
                playBTNDown = false;
            
            #endregion
            #region Exit Detection
            if (InputManager.MouseXLocation >= 487 && InputManager.MouseXLocation <= 553
             && InputManager.MouseYLocation >= 237 && InputManager.MouseYLocation <= 252)
                exitBTNDown = true;
            else
                exitBTNDown = false;
            #endregion

            if (InputManager.IsLButtonTriggered)
            {
                if (exitBTNDown)
                    this.Exit();
                else if (playBTNDown)
                {
                    isGameScreen = true;
                    isMainScreen = false;
                }
            }
        }

        void UpdateGameScreen()
        {
            #region Work Pile Locations
            if (InputManager.MouseXLocation >= 91 && InputManager.MouseXLocation <= 121 &&
                InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                workPile = 1;
            else if (InputManager.MouseXLocation >= 123 && InputManager.MouseXLocation <= 153 &&
                InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                workPile = 2;
            else if (InputManager.MouseXLocation >= 155 && InputManager.MouseXLocation <= 185 &&
                InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                workPile = 3;
            else if (InputManager.MouseXLocation >= 187 && InputManager.MouseXLocation <= 217 &&
                InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                workPile = 4;
            else
                workPile = 0;
            #endregion
            #region Community Pile Locations
            if (InputManager.MouseXLocation >= 273 && InputManager.MouseXLocation <= 303 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 1;
            else if (InputManager.MouseXLocation >= 305 && InputManager.MouseXLocation <= 335 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 2;
            else if (InputManager.MouseXLocation >= 337 && InputManager.MouseXLocation <= 367 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 3;
            else if (InputManager.MouseXLocation >= 369 && InputManager.MouseXLocation <= 399 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 4;
            else if (InputManager.MouseXLocation >= 401 && InputManager.MouseXLocation <= 431 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 5;
            else if (InputManager.MouseXLocation >= 433 && InputManager.MouseXLocation <= 463 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 6;
            else if (InputManager.MouseXLocation >= 465 && InputManager.MouseXLocation <= 495 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 7;
            else if (InputManager.MouseXLocation >= 497 && InputManager.MouseXLocation <= 527 &&
                InputManager.MouseYLocation >= 241 && InputManager.MouseYLocation <= 283)
                communePile = 8;
            else if (InputManager.MouseXLocation >= 273 && InputManager.MouseXLocation <= 303 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 9;
            else if (InputManager.MouseXLocation >= 305 && InputManager.MouseXLocation <= 335 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 10;
            else if (InputManager.MouseXLocation >= 337 && InputManager.MouseXLocation <= 367 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 11;
            else if (InputManager.MouseXLocation >= 369 && InputManager.MouseXLocation <= 399 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 12;
            else if (InputManager.MouseXLocation >= 401 && InputManager.MouseXLocation <= 431 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 13;
            else if (InputManager.MouseXLocation >= 433 && InputManager.MouseXLocation <= 463 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 14;
            else if (InputManager.MouseXLocation >= 465 && InputManager.MouseXLocation <= 495 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 15;
            else if (InputManager.MouseXLocation >= 497 && InputManager.MouseXLocation <= 527 &&
                InputManager.MouseYLocation >= 286 && InputManager.MouseYLocation <= 328)
                communePile = 16;
            else
                communePile = 0;
            #endregion
            #region Hand Selection
            if (InputManager.MouseXLocation  >= 59 && InputManager.MouseXLocation <=  89
             && InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                canSelectHand = true;
            else
                canSelectHand = false;

            if (canSelectHand && !workSelect && !schnelleSelect)
            {
                if (InputManager.IsLButtonTriggered)
                    handSelect = true;
            }
            else if (InputManager.IsRButtonTriggered && handSelect)
                    handSelect = false;

            if (InputManager.IsMButtonTriggered)
            {
                for (int i = 0; i <  3; i++)
                    playerDeck.Cards.Add(playerCards[i]);
                for (int i = 2; i >= 0; i--)
                    playerCards[i] = playerDeck.DealCard();
            }
            #endregion
            #region Work Pile Selection
            switch(workPile)
            {
                case 1:
                case 2:
                case 3:
                case 4:
                    canSelectWork = true;
                    break;

                default:
                    canSelectWork = false;
                    break;
            }
            if (canSelectWork && !handSelect && !schnelleSelect)
                if (InputManager.IsLButtonTriggered && !firstWork && !secondWork && !thirdWork && !fourthWork)
                {
                    switch (workPile)
                    {
                        case 1:
                            if (pFirst.Pile.Capacity == 0 || pFirst.Pile.Count > 0)
                            firstWork = true;
                            break;
                        case 2:
                            if (pSecond.Pile.Capacity == 0 || pSecond.Pile.Count > 0)
                                secondWork = true;
                            break;
                        case 3:
                            if (pThird.Pile.Capacity == 0 || pThird.Pile.Count > 0)
                            thirdWork = true;
                            break;
                        case 4:
                            if (pFourth.Pile.Capacity == 0 || pFourth.Pile.Count > 0)
                            fourthWork = true;
                            break;
                    }
                    workSelect = true;
                }
            else if (InputManager.IsRButtonTriggered && workSelect)
            {
                firstWork = false;
                secondWork = false;
                thirdWork = false;
                fourthWork = false;
                workSelect = false;
            }
            #endregion
            #region Schnelle Selection
            if (InputManager.MouseXLocation >= 226 && InputManager.MouseXLocation <= 256
            && InputManager.MouseYLocation >= 381 && InputManager.MouseYLocation <= 423)
                canSelectSchnelle = true;
            else
                canSelectSchnelle = false;

            if (canSelectSchnelle && !handSelect && !workSelect)
            {
                if (InputManager.IsLButtonTriggered)
                    schnelleSelect = true;
            }
            else if (InputManager.IsRButtonTriggered && schnelleSelect)
                schnelleSelect = false;
            #endregion

            if (handSelect)
            {
                if (playerCards[2] != null && InputManager.IsLButtonTriggered)
                {
                    #region Hand to Work
                    switch (workPile)
                    {
                        #region Case One
                        case 1:
                            if (pFirst.CanAddCard(playerCards[2]))
                            {
                                pFirst.Pile.Add(playerCards[2]);
                                addedCard = true;
                            }
                            break;
                        #endregion
                        #region Case Two
                        case 2:
                            if (pSecond.CanAddCard(playerCards[2]))
                            {
                                pSecond.Pile.Add(playerCards[2]);
                                addedCard = true;
                            }
                            break;
                        #endregion
                        #region Case Three
                        case 3:
                            if (pThird.CanAddCard(playerCards[2]))
                            {
                                pThird.Pile.Add(playerCards[2]);
                                addedCard = true;
                            }
                            break;
                        #endregion
                        #region Case Four
                        case 4:
                            if (pFourth.CanAddCard(playerCards[2]))
                            {
                                pFourth.Pile.Add(playerCards[2]);
                                addedCard = true;
                            }
                            break;
                        #endregion
                    }
                    #endregion
                    #region Hand to Commune
                    switch (communePile)
                    {
                        #region Cases
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        #endregion
                            if (InputManager.IsLButtonTriggered &&
                               communityPiles[communePile - 1].CanAddCard(playerCards[2]))
                            {
                                communityPiles[communePile - 1].Pile.Add(playerCards[2]);
                                addedCard = true;
                            }
                            break;
                    }
                    #endregion
                    if (addedCard)
                    {
                        #region Update Hand
                        if (playerCards[1] != null)
                            playerCards[2] = playerCards[1];
                        else
                            playerCards[2] = null;

                        if (playerCards[0] != null)
                            playerCards[1] = playerCards[0];
                        else
                            playerCards[1] = null;

                        if (playerDeck.Cards.Count > 0)
                            playerCards[0] = playerDeck.DealCard();
                        else
                            playerCards[0] = null;
                        #endregion
                    }
                }
                addedCard = false;
                workPile = 0;
            }
            #region Schnelle to Work

            #endregion
            #region Work to Work
            if (workSelect)
            {
                if (firstWork && pFirst.Pile.Capacity > 0)
                {
                    #region First Work Pile Functionality
                    switch (workPile)
                    {
                        case 2:
                            if (InputManager.IsLButtonTriggered && pSecond.CanAddCard(pFirst.Pile.Last<Card>()))
                            {
                                pSecond.Pile.Add(pFirst.Pile.Last<Card>());
                                pFirst.Pile.Remove(pFirst.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = true;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 3:
                            if (InputManager.IsLButtonTriggered && pThird.CanAddCard(pFirst.Pile.Last<Card>()))
                            {
                                pThird.Pile.Add(pFirst.Pile.Last<Card>());
                                pFirst.Pile.Remove(pFirst.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = true;
                                fourthWork = false;
                            }
                            break;
                        case 4:
                            if (InputManager.IsLButtonTriggered && pFourth.CanAddCard(pFirst.Pile.Last<Card>()))
                            {
                                pFourth.Pile.Add(pFirst.Pile.Last<Card>());
                                pFirst.Pile.Remove(pFirst.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = false;
                                fourthWork = true;
                            }
                            break;
                    }
                    #endregion
                }
                if (secondWork && (pSecond.Pile.Capacity > 0))
                {
                    #region Second Work Pile Functionality
                    switch (workPile)
                    {
                        case 1:
                            if (InputManager.IsLButtonTriggered && pFirst.CanAddCard(pSecond.Pile.Last<Card>()))
                            {
                                pFirst.Pile.Add(pSecond.Pile.Last<Card>());
                                pSecond.Pile.Remove(pSecond.Pile.Last<Card>());
                                firstWork = true;
                                secondWork = false;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 3:
                            if (InputManager.IsLButtonTriggered && pThird.CanAddCard(pSecond.Pile.Last<Card>()))
                            {
                                pThird.Pile.Add(pSecond.Pile.Last<Card>());
                                pSecond.Pile.Remove(pSecond.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = true;
                                fourthWork = false;
                            }
                            break;
                        case 4:
                            if (InputManager.IsLButtonTriggered && pFourth.CanAddCard(pSecond.Pile.Last<Card>()))
                            {
                                pFourth.Pile.Add(pSecond.Pile.Last<Card>());
                                pSecond.Pile.Remove(pSecond.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = false;
                                fourthWork = true;
                            }
                            break;
                    }
                    #endregion
                }
                if (thirdWork && pThird.Pile.Capacity > 0)
                {
                    #region Third Work Pile Functionality
                    switch (workPile)
                    {
                        case 1:
                            if (InputManager.IsLButtonTriggered && pFirst.CanAddCard(pThird.Pile.Last<Card>()))
                            {
                                pFirst.Pile.Add(pThird.Pile.Last<Card>());
                                pThird.Pile.Remove(pThird.Pile.Last<Card>());
                                firstWork = true;
                                secondWork = false;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 2:
                            if (InputManager.IsLButtonTriggered && pSecond.CanAddCard(pThird.Pile.Last<Card>()))
                            {
                                pSecond.Pile.Add(pThird.Pile.Last<Card>());
                                pThird.Pile.Remove(pThird.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = true;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 4:
                            if (InputManager.IsLButtonTriggered && pFourth.CanAddCard(pThird.Pile.Last<Card>()))
                            {
                                pFourth.Pile.Add(pThird.Pile.Last<Card>());
                                pThird.Pile.Remove(pThird.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = false;
                                fourthWork = true;
                            }
                            break;
                    }
                    #endregion
                }
                if (fourthWork && pFourth.Pile.Capacity > 0)
                {
                    #region Fourth Work Pile Functionality
                    switch (workPile)
                    {
                        case 1:
                            if (InputManager.IsLButtonTriggered && pFirst.CanAddCard(pFourth.Pile.Last<Card>()))
                            {
                                pFirst.Pile.Add(pFourth.Pile.Last<Card>());
                                pFourth.Pile.Remove(pFourth.Pile.Last<Card>());
                                firstWork = true;
                                secondWork = true;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 2:
                            if (InputManager.IsLButtonTriggered && pSecond.CanAddCard(pFourth.Pile.Last<Card>()))
                            {
                                pSecond.Pile.Add(pFourth.Pile.Last<Card>());
                                pFourth.Pile.Remove(pFourth.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = true;
                                thirdWork = false;
                                fourthWork = false;
                            }
                            break;
                        case 3:
                            if (InputManager.IsLButtonTriggered && pThird.CanAddCard(pFourth.Pile.Last<Card>()))
                            {
                                pThird.Pile.Add(pFourth.Pile.Last<Card>());
                                pFourth.Pile.Remove(pFourth.Pile.Last<Card>());
                                firstWork = false;
                                secondWork = false;
                                thirdWork = true;
                                fourthWork = false;
                            }
                            break;
                    }
                    #endregion
                }
                workPile = 0;
            }
            #endregion
            #region Work to Commune
            if (workSelect)
            {
                if (firstWork && pFirst.Pile.Capacity > 0)
                {
                    switch (communePile)
                    {
                        #region Cases
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        #endregion
                            if (InputManager.IsLButtonTriggered &&
                               communityPiles[communePile - 1].CanAddCard(pFirst.Pile.Last<Card>()))
                            {
                                communityPiles[communePile - 1].Pile.Add(pFirst.Pile.Last<Card>());
                                pFirst.Pile.Remove(pFirst.Pile.Last<Card>());
                                firstWork = false;
                            }
                            break;
                    }
                }
                if (secondWork && pSecond.Pile.Capacity > 0)
                {
                    switch (communePile)
                    {
                        #region Cases
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        #endregion
                            if (InputManager.IsLButtonTriggered &&
                               communityPiles[communePile - 1].CanAddCard(pSecond.Pile.Last<Card>()))
                            {
                                communityPiles[communePile - 1].Pile.Add(pSecond.Pile.Last<Card>());
                                pSecond.Pile.Remove(pSecond.Pile.Last<Card>());
                                secondWork = false;
                            }
                            break;
                    }
                }
                if (thirdWork && pThird.Pile.Capacity > 0)
                {
                    switch (communePile)
                    {
                        #region Cases
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        #endregion
                            if (InputManager.IsLButtonTriggered &&
                               communityPiles[communePile - 1].CanAddCard(pThird.Pile.Last<Card>()))
                            {
                                communityPiles[communePile - 1].Pile.Add(pThird.Pile.Last<Card>());
                                pThird.Pile.Remove(pThird.Pile.Last<Card>());
                                thirdWork = false;
                            }
                            break;
                    }
                }
                if (fourthWork && pFourth.Pile.Capacity > 0)
                {
                    switch (communePile)
                    {
                        #region Cases
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        #endregion
                            if (InputManager.IsLButtonTriggered &&
                                communityPiles[communePile - 1].CanAddCard(pFourth.Pile.Last<Card>()))
                            {
                                communityPiles[communePile - 1].Pile.Add(pFourth.Pile.Last<Card>());
                                pFourth.Pile.Remove(pFourth.Pile.Last<Card>());
                                fourthWork = false;
                            }
                            break;
                    }
                }
            }
            #endregion
        }
        
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            if (isMainScreen)
                DrawMainScreen();
            else if (isGameScreen)
                DrawGameScreen();

            spriteBatch.End();
            base.Draw(gameTime);
        }

        void DrawMainScreen()
        {
            spriteBatch.Draw(mainMenu, Vector2.Zero, Color.White);
            spriteBatch.Draw(buttonBackground, new Vector2(485, 215), Color.White);
            spriteBatch.Draw(playBTNDown ? disPlayBTN : playBTN, new Vector2(485, 215), Color.White);
            spriteBatch.Draw(exitBTNDown ? disExitBTN : exitBTN, new Vector2(485, 235), Color.White);
        } 

        void DrawGameScreen()
        {
            spriteBatch.Draw(gamePlayScreen, Vector2.Zero, Color.White);
            #region Community Piles
            for (int i = 0; i < 16; i++)
            {
                int x;
                int y;

                if (i >= 8)
                {
                    y = 286;
                    x = 273 + (i - 8) * 32;
                }
                else
                {
                    y = 241;
                    x = 273 + (i * 32);
                }

                spriteBatch.Draw(outlineRing, new Vector2(x, y), Color.White);
                if (communityPiles[i].Pile.Capacity > 0)
                    foreach (Card c in communityPiles[i].Pile)
                    {
                        if (c != null)
                            c.Draw(spriteBatch, new Vector2(x, y));
                    }
            }
            #endregion

            #region Player's Cards
            //Deck
            if(playerDeck.Cards != null)
                playerDeck.Draw(spriteBatch, 7, 381);
            //Hand
            for(int i = 0; i < 3; i++)
            {
                if (playerCards[i] != null)
                    playerCards[i].Draw(spriteBatch, new Vector2(39 + (i * 10), 381));
            }
            if (handSelect)
                spriteBatch.Draw(selectionRing, new Vector2(59, 381), Color.White);
            //Schnelle Karten Pile
            pSchnelle[pSchnelleCard].Draw(spriteBatch, new Vector2(226, 381));
            //Work Piles
            //First
            spriteBatch.Draw(outlineRing, new Vector2(91, 381), Color.White);
            for (int i = 0; i < pFirst.Pile.Count; i++)
            {
                if (pFirst.Pile[i] != null)
                {
                    pFirst.Pile[i].Draw(spriteBatch, new Vector2(91, 381 + (i * 8)));
                    if (firstWork && pFirst.Pile[i].Equals(pFirst.Pile.Last<Card>()))
                        spriteBatch.Draw(selectionRing, new Vector2(91, 381 + (i * 8)), Color.White);
                }
            }
            //Second
            spriteBatch.Draw(outlineRing, new Vector2(123, 381), Color.White);
            for (int i = 0; i < pSecond.Pile.Count; i++)
            {
                if (pSecond.Pile[i] != null)
                    pSecond.Pile[i].Draw(spriteBatch, new Vector2(123, 381 + (i * 8)));
                if (secondWork && pSecond.Pile[i].Equals(pSecond.Pile.Last<Card>()))
                    spriteBatch.Draw(selectionRing, new Vector2(123, 381 + (i * 8)), Color.White);
            }
            //Third
            spriteBatch.Draw(outlineRing, new Vector2(155, 381), Color.White);
            for (int i = 0; i < pThird.Pile.Count; i++)
            {
                if (pThird.Pile[i] != null)
                    pThird.Pile[i].Draw(spriteBatch, new Vector2(155, 381 + (i * 8)));
                if (thirdWork && pThird.Pile[i].Equals(pThird.Pile.Last<Card>()))
                    spriteBatch.Draw(selectionRing, new Vector2(155, 381 + (i * 8)), Color.White);
            }
            //Fourth
            spriteBatch.Draw(outlineRing, new Vector2(187, 381), Color.White);
            for (int i = 0; i < pFourth.Pile.Count; i++)
            {
                if (pFourth.Pile[i] != null)
                    pFourth.Pile[i].Draw(spriteBatch, new Vector2(187, 381 + (i * 8)));
                if (fourthWork && pFourth.Pile[i].Equals(pFourth.Pile.Last<Card>()))
                    spriteBatch.Draw(selectionRing, new Vector2(187, 381 + (i * 8)), Color.White);
            }
            #endregion
            #region Computer One's Cards
            //Deck
            cOneDeck.Draw(spriteBatch, 544, 381);
            //Hand

            //Work Piles

            //Schnelle Karten Piles
            #endregion
            #region Computer Two's Cards
            //Deck
            cTwoDeck.Draw(spriteBatch, 763, 146);
            //Hand

            //Work Piles

            //Schnelle Karten Piles
            #endregion
            #region Computer Three's Cards
            //Deck
            cTreDeck.Draw(spriteBatch, 226, 146);
            //Hand

            //Work Piles

            //Schnelle Karten Piles
            #endregion
        }
    }
}
